package edu.uwm.universitydb.dao.project;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import edu.uwm.universitydb.model.Project;

public class SearchProjectByIDCommand extends SearchProjectCommandBase<Project> {
	  /** sql portion representing where clause for name */
    private static final String SQL_WHERE_CLAUSE_NAME = " WHERE p.pno = ? and "+
	  "university.manage.pno = p.pno AND prof.prof_ssn = university.manage.prof_ssn "+
        "AND prof.prof_ssn = university.works.prof_ssn AND "+
	  "university.works.dno = dept.dno ORDER BY p.pno;";

    /** attribute holding the ssn */
    private final Integer mPid;

    /**
     * 
     * @param pid
     */
    public SearchProjectByIDCommand(final int id)
    {
    	mPid = id;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DataFetchCommand#processResult(java.sql.ResultSet)
     */
    @Override
    public Project processResult(final ResultSet result) throws SQLException
    {
        if (result.next())
        {
            return getProject(result);
        }
        return null;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#getSQL()
     */
    @Override
    public String getSQL()
    {
        return SELECT_SQL + SQL_WHERE_CLAUSE_NAME;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.framework.db.command.DBCommand#setParameters(java.sql.PreparedStatement)
     */
    @Override
    public void setParameters(final PreparedStatement pStmt) throws SQLException
    {
        pStmt.setInt(1, mPid);
    }
}
